package com.ali.framework.utils;

import android.os.Environment;

import java.io.File;

/**
 * Created by Unborn on 2020/6/23.
 */
public class PathManger {
    // 根路径
    private static final String ROOT_PATH = getSDPath() + "/DSV";
    private static final String APK_PATH = ROOT_PATH + "/apk";
    private static final String CRASH_PATH = ROOT_PATH + "/crash_report";
    private static final String IMAGE_PATH = ROOT_PATH + "/images";
    public static final String IMAGE_CACHE_PATH = ROOT_PATH + "/imageloader/.cache";

    static String getSDPath() {
        File sdDir = null;
        // 判断sd卡是否存在
        boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
        if (sdCardExist) {
            // 获取跟目录
            sdDir = Environment.getExternalStorageDirectory();
        }
        if (sdDir == null) {
            return "";
        } else {
            return sdDir.getAbsolutePath();
        }
    }

    public static File getApkDir() {
        File file = new File(APK_PATH);
        if (!file.exists()) {
            file.mkdirs();
        }
        return file;
    }

    public static String getApkPath() {
        File file = new File(APK_PATH);
        if (!file.exists()) {
            file.mkdirs();
        }
        return APK_PATH;
    }

    public static String getPhotoPath() {
        File file = new File(IMAGE_PATH);
        if (!file.exists()) {
            file.mkdirs();
        }
        return IMAGE_PATH;
    }

    public static File getPhotoDir() {
        File file = new File(IMAGE_PATH);
        if (!file.exists()) {
            file.mkdirs();
        }
        return file;
    }

    public static File getImageCacheDir() {
        File file = new File(IMAGE_CACHE_PATH);
        if (!file.exists()) {
            file.mkdirs();
        }
        return file;
    }

    public static String getImageCachePath() {
        File file = new File(IMAGE_CACHE_PATH);
        if (!file.exists()) {
            file.mkdirs();
        }
        return IMAGE_CACHE_PATH;
    }

    public static File getCrashReportDir() {
        File file = new File(CRASH_PATH);
        if (!file.exists()) {
            file.mkdirs();
        }
        return file;
    }

    public static String getCrashReportPath() {
        File file = new File(CRASH_PATH);
        if (!file.exists()) {
            file.mkdirs();
        }
        return CRASH_PATH;
    }
}